Skip to content

ssh-cipher: make Encryptor and Decryptor generic around cipher#533

Merged
tarcieri merged 1 commit into
masterfrom
ssh-cipher/typed-encryptor-and-decryptor
May 24, 2026
Merged

ssh-cipher: make Encryptor and Decryptor generic around cipher#533
tarcieri merged 1 commit into
masterfrom
ssh-cipher/typed-encryptor-and-decryptor

Conversation

@tarcieri
Copy link
Copy Markdown
Member

Adds a BlockCipher extension trait and defines it for the internally defined multi-key-size Aes type as well as des::TdesEde3 which is now re-exported as ssh_cipher::block_cipher::Tdes.

The Decryptor and Encryptor types are now generic around a sealed BlockCipher trait, and have AesDecryptor/AesEncryptor and TdesDecryptor/TdesEncryptor type aliases. They both support CBC mode, and AES ciphers support CTR too. The API is otherwise the same except callers need to use one of the typed *Encryptor/*Decryptor traits.

The crate now implements both block cipher modes of operation internally and no longer relies on the cbc and ctr crates. This makes dynamically dispatching between the two modes easier while avoiding some monomorphization bloat, and actually doesn't add significant complexity.

With Decryptor/Encryptor now well-typed and supporting typed block sizes, it should be possible to make them impelement the BlockMode* traits and therefore make them work like the other block modes, but that particular change is deferred for a followup PR.

Adds a `BlockCipher` extension trait and defines it for the internally
defined multi-key-size `Aes` type as well as `des::TdesEde3` which is
now re-exported as `ssh_cipher::block_cipher::Tdes`.

The `Decryptor` and `Encryptor` types are now generic around a sealed
`BlockCipher` trait, and have `AesDecryptor`/`AesEncryptor` and
`TdesDecryptor`/`TdesEncryptor` type aliases. They both support CBC
mode, and AES ciphers support CTR too. The API is otherwise the same
except callers need to use one of the typed `*Encryptor`/`*Decryptor`
traits.

The crate now implements both block cipher modes of operation internally
and no longer relies on the `cbc` and `ctr` crates. This makes
dynamically dispatching between the two modes easier while avoiding some
monomorphization bloat, and actually doesn't add significant complexity.

With `Decryptor`/`Encryptor` now well-typed and supporting typed block
sizes, it should be possible to make them impelement the `BlockMode*`
traits and therefore make them work like the other block modes, but that
particular change is deferred for a followup PR.
@tarcieri tarcieri force-pushed the ssh-cipher/typed-encryptor-and-decryptor branch from e64a7ac to 3c89a3c Compare May 24, 2026 22:10
@tarcieri tarcieri merged commit bb1db47 into master May 24, 2026
32 checks passed
@tarcieri tarcieri deleted the ssh-cipher/typed-encryptor-and-decryptor branch May 24, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant